package dev.common.utils;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class HttpUtil {

	public static JSONObject resValue(boolean isSuccess, String msg, Object data) {
		JSONObject returnValue = new JSONObject();
		returnValue.put("success", isSuccess);
		returnValue.put("msg", msg);
		returnValue.put("data", data);
		return returnValue;
	}

	public static Map<String, String> getRequestParams(HttpServletRequest request) {
		Map<String, String> map = new HashMap<>();
		Map<String, String[]> params = request.getParameterMap();
		for (Entry<String, String[]> entries : params.entrySet()) {
			map.put(entries.getKey(), entries.getValue()[0]);
		}
		return map;
	}
}